package com.chen.springcloud.demo.client.fallback;

import com.chen.springcloud.demo.client.remote.UAAClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Feign 客户端接口的 Fallback 回退处理工厂类
 * @author chentian
 * @date 2021/12/26
 */
@Slf4j
@Component
public class UAAClientFallbackFactory implements FallbackFactory<UAAClient> {

    /**
     * 创建 UAAClient 客户端的回退处理实例
     */
    @Override
    public UAAClient create(Throwable cause) {
        log.error("RPC调用异常，回退！", cause);

        // 创建一个 UAAClient 客户端接口的匿名回退实例
        return new UAAClient() {
            @Override
            public String hello() {
                return "default hello world!";
            }

            @Override
            public String word(String word) {
                return "FallbackFactory fallback: uaa word rest 服务调用失败";
            }
        };
    }
}
